/*
Author: Surpass-HC
Source: https://gitee.com/hxchuan000/clpc-1
Mail: surpass-hc@qq.com
*/
#include <cplTime.h>
static const char DEV_C51_CODE_FLAG mouthBuf[][4] = {
    "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
// 20250408163540
// ostr need >= 14 byte.
// need usr input date str(__DATE__), and time str(__TIME__).
// <Jul  5 2025> <10:27:40>
int getCompileTime(const char *datep, const char *timep, char *ostr)
{
    int i;
    const char *tmpPtr;
    int dateLen;
    if (!(ostr && datep && timep))
    {
        return -1;
    }
    // date
    tmpPtr = datep;
    dateLen = strlen(datep);
    ostr[0] = tmpPtr[dateLen - 4];
    ostr[1] = tmpPtr[dateLen - 3];
    ostr[2] = tmpPtr[dateLen - 2];
    ostr[3] = tmpPtr[dateLen - 1];
    for (i = 0; i < 12; i++)
    {
        if (!(tmpPtr[0] == mouthBuf[i][0] && tmpPtr[1] == mouthBuf[i][1] && tmpPtr[2] == mouthBuf[i][2]))
        {
            continue;
        }
        ostr[4] = (i + 1) / 10 + '0';
        ostr[5] = (i + 1) % 10 + '0';
        break;
    }
    if (tmpPtr[4] == ' ')
    {
        ostr[6] = '0';
    }
    else
    {
        ostr[6] = tmpPtr[4];
    }
    ostr[7] = tmpPtr[5];
    // time
    tmpPtr = timep;
    ostr[8] = tmpPtr[0];
    ostr[9] = tmpPtr[1];
    ostr[10] = tmpPtr[3];
    ostr[11] = tmpPtr[4];
    ostr[12] = tmpPtr[6];
    ostr[13] = tmpPtr[7];
    return 14;
}
